package com.kotlin.baselib.utils

import android.content.Context
import android.net.ConnectivityManager


object NetUtil {

    /**
     * 网络是否可用
     */
    fun isAvailable(mContext:Context):Boolean{
        val connManager = mContext.getSystemService(Context.CONNECTIVITY_SERVICE)  as ConnectivityManager
        val networkInfo =connManager.activeNetworkInfo
        return networkInfo!=null && networkInfo.isConnected
    }

    /*
      检测wifi是否连接
   */
    fun isWifiConnected(context: Context): Boolean {
        val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkInfo = cm.activeNetworkInfo
        return networkInfo != null && networkInfo.type == ConnectivityManager.TYPE_WIFI
    }

    /*
        检测手机信号是否连接
     */
    fun isPhoneConnected(context: Context): Boolean {
        val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkInfo = cm.activeNetworkInfo
        return networkInfo != null && networkInfo.type == ConnectivityManager.TYPE_MOBILE
    }
}